package logic

import (
	"context"
	"goods_srv/goods"
	"goods_srv/internal/svc"
	"goods_srv/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodsLogic {
	return &CreateGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateGoodsLogic) CreateGoods(in *goods.CreateGoodsRequest) (*goods.CreateGoodsResponse, error) {
	g := mysql.Goods{
		GoodsTitle: in.GoodsTitle,
		GoodsPrice: in.GoodsPrice,
		GoodsStock: in.GoodsStock,
		GoodsCover: in.GoodsCover,
	}
	err := g.Create()
	if err != nil {
		logx.Error("创建失败")
		return nil, err
	}
	return &goods.CreateGoodsResponse{}, nil
}
